package scantask.client.threeDObjects;

import gov.nasa.worldwind.layers.AirspaceLayer;

import java.awt.Color;

import scantask.client.threeDObjects.exceptions.LeafPolygoneException;
import scantask.containers.Coordinate;

public abstract class LeafPolygone implements ComponentPolygone{
	
	protected Color _color;
	protected double _xCenter;
	protected double _yCenter;
	protected double _buttom;
	protected double _up;
	protected int _angle;
	protected double _value;
	protected String _description;
	protected gov.nasa.worldwind.render.airspaces.AbstractAirspace _shape3D;
	protected AirspaceLayer _layer;
	
	public LeafPolygone(Color color, double xCenter, double yCenter, 
						double buttom, double up, int angle, double value) {
		//TODO add exceptions for illegal values
		this._color = color;
		this._xCenter = xCenter;
		this._yCenter = yCenter;
		this._buttom = buttom;
		this._up = up;
		this._angle = angle;
		this._value = value;
		this._description = "";
		this._layer = null;
	}

	@Override
	public void add(ComponentPolygone polygone) throws LeafPolygoneException {
		scantask.client.utilities.logging.SingletonLogger.getLogger().warning("Fail - Can't add polygone to leaf object");
		throw new LeafPolygoneException();
	}

	@Override
	public abstract ComponentPolygone clone();

	@Override
	public void draw(){
		this._layer.addAirspace(this._shape3D);
	}

	@Override
	public boolean isLeaf() {
		return true;
	}

	@Override
	public void setLocation(Coordinate coordinate) {
		this._xCenter = this._xCenter + coordinate.getX();
		this._yCenter = this._yCenter + coordinate.getY();
	}
	
	@Override
	public void setDescription(String desc){
		this._description = desc;
		this._shape3D.setDescription(desc);
	}
	
	@Override
	public String getDescription(){
		return this._description;
	}
	
	public void setColor(Color color) {
		//TODO add exception for illegal value
		this._color = color;
	}
	
	public void setButtom(double buttom) {
		//TODO add exception for illegal value
		this._buttom = buttom;
	}
	
	public void setUp(double up) {
		//TODO add exception for illegal value
		this._up = up;
	}
	
	public void addValueToUp(double up) {
		//TODO add exception for illegal value
		this._up += up;
	}
	
	public void setAngle(int angle) {
		//TODO add exception for illegal value
		this._angle = angle;
	}
	
	public void setValue(double value) {
		//TODO add exception for illegal value
		this._value = value;
	}
	
	public double getValue(){
		return this._value;
	}

	public void init3DObject(AirspaceLayer layer){
		this._layer = layer;
		
	}
	
	public void moveUp(double amount) {
		this._buttom += amount;
		this._up += amount;
	}
}
